<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">

<head th:replace="admin/_fragments :: head(~{::title})">
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>图书管理</title>

    <!--    预览路径 ,可以直接在 IDEA 打开 。如果不导入两遍就预览不了 -->
    <link rel="icon" href="../../static/favicon.ico" type="image/x-icon">
    <!--导入网页图标 -->
    <link rel="shortcut icon" href="../../static/favicon.ico" type="image/x-icon">
    <!--导入网页图标 -->
    <script src="../../static/lib/jQuery/jquery-3.5.1.min.js"></script>
    <!--导入jQuery库 -->
    <script src="../../static/lib/layui/layui.js"></script>
    <!--导入layUI库 -->
    <script src="../../static/lib/cookie/js.cookie-2.2.1.min.js"></script>
    <!--导入cookie库 -->
    <link rel="stylesheet" href="../../static/lib/layui/css/layui.css" media="all">
    <!--导入layUI css库 -->
    <link rel="stylesheet" href="../../static/css/common.css">
    <!--导入公共的css，其中可定义整个网页的配色方案 -->

</head>

<body class="layui-layout-body">
<div class="layui-layout layui-layout-admin">
    <!-- 页面的header -->
    <div th:replace="admin/_fragments :: admin-header" class="layui-header">
        <div class="layui-logo">图书管理系统</div>
        <!-- 头部区域（可配合layui已有的水平导航） -->
        <ul class="layui-nav layui-layout-left">
            <li class="layui-nav-item"><a class="layui-icon layui-icon-shrink-right" href="javascript:void(0)"></a>
            </li>
            <!--菜单按钮-->

            <!-- <li class="layui-nav-item"><a href="">控制台</a></li>
            <li class="layui-nav-item"><a href="">图书管理</a></li>
            <li class="layui-nav-item"><a href="">用户</a></li>
            <li class="layui-nav-item">
                <a href="javascript:;">其它系统</a>
                <dl class="layui-nav-child">
                    <dd><a href="">邮件管理</a></dd>
                    <dd><a href="">消息管理</a></dd>
                    <dd><a href="">授权管理</a></dd>
                </dl>
            </li> -->

        </ul>
        <ul class="layui-nav layui-layout-right">
            <li class="layui-nav-item">
                <a href="javascript:void(0)">
                    <img src="../../static/images/ashini.ico" class="layui-nav-img">
                    啊、是你
                </a>
                <dl class="layui-nav-child">
                    <dd><a href="">基本资料</a></dd>
                    <dd><a href="">安全设置</a></dd>
                </dl>
            </li>
            <li class="layui-nav-item"><a href="/admin/login">安全退出</a></li>
        </ul>
    </div>
    <!-- 页面的menu/左边的导航栏 -->
    <div th:replace="admin/_fragments :: admin-menu" id="div_side_bg" class="layui-side layui-bg-black">
        <div class="layui-side-scroll">
            <!-- 左侧导航区域（可配合layui已有的垂直导航） -->
            <ul class="layui-nav layui-nav-tree" lay-filter="test">
                <li class="layui-nav-item">
                    <a class="" href="javascript:void(0)">用户管理</a>
                    <dl class="layui-nav-child">
                        <dd><a href="javascript:void(0)">用户列表</a></dd>
                        <dd><a href="javascript:void(0)">权限列表</a></dd>
                    </dl>
                </li>
                <li class="layui-nav-item  layui-nav-itemed">
                    <a href="javascript:void(0)">图书管理</a>
                    <dl class="layui-nav-child">
                        <dd class="layui-this"><a href="javascript:void(0)" th:href="@{/admin/book-list}">图书列表</a></dd>
                        <dd><a href="javascript:void(0)">图书类别列表</a></dd>
                    </dl>
                </li>
                <li class="layui-nav-item">
                    <a class="" href="javascript:void(0)">借阅管理</a>
                    <dl class="layui-nav-child">
                        <dd><a href="javascript:void(0)">列表一</a></dd>
                        <dd><a href="javascript:void(0)">列表二</a></dd>
                        <dd><a href="javascript:void(0)">列表三</a></dd>
                    </dl>
                </li>
                <!--                    <li class="layui-nav-item"><a href="">云市场</a></li>-->
                <!--                    <li class="layui-nav-item"><a href="">发布商品</a></li>-->
            </ul>
        </div>
    </div>
    <div class="layui-body">
        <!-- 内容主体区域 -->
        <div style="width: 100%;height:98%;padding-left: 15px;padding-top: 10px;">
            <!-- 面包屑-->
            <span class="layui-breadcrumb" lay-separator=" | ">
                <a href="/admin/index">首页</a>
                <a href="/book/admin/book-list">图书管理</a>
                <a><cite th:text="${operation}">添加新图书</cite></a>
            </span>

            <form class="layui-form layui-form-pane" style="margin-top: 10px;" action="" th:object="${book}"
                  th:action="@{/book/save}">

                <div class="layui-form-item">
                    <div class="layui-input-block">
                        <input name="bookId" th:value="*{bookId}" type="hidden" autocomplete="off" class="layui-input">
                    </div>
                </div>

                <div class="layui-form-item">
                    <label class="layui-form-label">图书名称</label>
                    <div class="layui-input-block">
                        <input type="text" name="bookName" th:value="*{bookName}" lay-verify="required"
                               lay-reqtext="图书类别名称不可以为空" placeholder="请输入" autocomplete="off" class="layui-input">
                    </div>
                </div>


                <div class="layui-form-item">
                    <label class="layui-form-label">图书类别</label>
                    <div class="layui-input-block">
                        <select name="type.typeId" lay-filter="type">
                            <option th:selected="${book.type!=null?book.type.typeId==type.typeId:0}"
                                    th:each="type : ${types}" th:value="${type.typeId}" th:text="${type.typename}"
                                    value=""></option>
                        </select>
                    </div>
                </div>

                <div class="layui-form-item">
                    <label class="layui-form-label">图书作者</label>
                    <div class="layui-input-block">
                        <input type="text" name="bookWriter" th:value="*{bookWriter}" lay-verify="required"
                               lay-reqtext="图书类别名称不可以为空" placeholder="请输入" autocomplete="off" class="layui-input">
                    </div>
                </div>

                <div class="layui-form-item">
                    <div class="layui-inline">
                        <label class="layui-form-label">馆藏总数</label>
                        <div class="layui-input-inline">
                            <input type="text" name="bookSumNumber" th:value="*{bookSumNumber}"
                                   lay-verify="required|number" autocomplete="off"
                                   class="layui-input">
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label">当前库存</label>
                        <div class="layui-input-inline">
                            <input type="text" name="bookNumber" th:value="*{bookNumber}" lay-verify="required|number"
                                   autocomplete="off"
                                   class="layui-input">
                        </div>
                    </div>

                    <div class="layui-inline">
                        <label class="layui-form-label">单价</label>
                        <div class="layui-input-inline">
                            <input type="text" name="bookPrice" th:value="*{bookPrice}" lay-verify="required|number"
                                   autocomplete="off"
                                   class="layui-input">
                        </div>
                    </div>
                </div>

                <div class="layui-form-item layui-form-text">
                    <label class="layui-form-label">内容简介</label>
                    <div class="layui-input-block">
                        <!--                        <input type="hidden" name="bookDescription" th:value="*{bookDescription}" >-->
                        <textarea placeholder="请输入内容" name="bookDescription" th:text="*{bookDescription}"
                                  class="layui-textarea"></textarea>
                    </div>
                </div>

                <div class="layui-upload-list">
                    <img class="layui-upload-img book_picture" id="pic">
                    <p id="demoText"></p>
                    <input type="hidden" name="picture" id="pic_v" th:value="*{picture}">
                </div>

                <div class="layui-upload">

                        <button type="button" class="layui-btn layui-btn-normal" id="test1" style="width: 120px">上传图片</button>

                        <button type="reset" class="layui-btn layui-btn-primary" style="margin-left: 20px;margin-right: 9px">重置</button>

                        <button type="submit" class="layui-btn" lay-submit="" lay-filter="demo1">保存</button>


                </div>
            </form>

        </div>
    </div>

    <div th:replace="admin/_fragments :: admin-footer" class="layui-footer">
        <!-- 底部固定区域 -->
        ©2020 版权归武汉理工大学计算机1702"我都行，你们商量吧"小组所有&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
        <span style="color:rgb(144, 145, 146)">
                技术支持：https://www.layui.com/
            </span>
    </div>
</div>


<!--导入公共的js，其中实现了菜单按钮的点击事件-->
<script src="../../static/js/common.js" th:src="@{/js/common.js}"></script>

<!-- layUI执行脚本 -->
<script>
    layui.use(['element', 'form', 'upload'], function () {
        var form = layui.form;
        var element = layui.element;
        var $ = layui.jquery,upload = layui.upload;

        var picture = $("#pic_v").val();
        if(picture!=null&&picture!==""){
            $("#pic").attr("src",picture)
        }else{
            $("#pic").attr("src","/images/default.png")
        }

        //普通图片上传
        var uploadInst = upload.render({
            elem: '#test1'
            ,url: 'http://121.40.126.170/upload/' //改成您自己的上传接口
            ,before: function(obj){
                //预读本地文件示例，不支持ie8
                obj.preview(function(index, file, result){
                    $('#demo1').attr('src', result); //图片链接（base64）
                });
            }
            ,done: function(res){
                //如果上传失败
                if(res.code > 0){
                    return layer.msg('上传失败');
                }else{
                    //上传成功
                   // layer.alert('上传成功，url是'+res.pictureURL);
                    $("#pic_v").val(res.pictureURL);
                    $("#pic").attr("src",res.pictureURL);
                }
            }
            ,error: function(){
                //演示失败状态，并实现重传
                var demoText = $('#demoText');
                demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-xs demo-reload">重试</a>');
                demoText.find('.demo-reload').on('click', function(){
                    uploadInst.upload();
                });
            }
        });

    });
</script>


<!--author : 计算机1702  zhao fan -->
</body>

</html>